from django.utils.deprecation import MiddlewareMixin


class AMiddleware(MiddlewareMixin):
    def process_request(self, request):
        request.ten = 'ten'
        print('A process_request')

    def process_view(self, request, callback, callback_args, callback_kwargs):
        print('A process_view')
        # return callback(request, *callback_args, **callback_kwargs)

    def process_exception(self, request, exception):
        # return JsonResponse({'ok':False, 'msg':str(exception)})
        print('A process_exception')

    def process_response(self, request, response):
        print('A process_response')
        return response


class BMiddleware(MiddlewareMixin):
    def process_request(self, request):
        print('B process_request')

    def process_view(self, request, callback, callback_args, callback_kwargs):
        print('B process_view')

    def process_exception(self, request, exception):
        print('B process_exception')

    def process_response(self, request, response):
        print('B process_response')
        return response
